<?php

namespace app\controllers;

use core\{Session};
use app\models\UserModel;

class User extends \core\Controller
{
    // public function __construct()
    // {
    //     if (! isLogged()) {
    //         redirect(url('/login'));
    //     }
    // }

    public function index()
    {
        $this->pageInfo = ['title' => '用户'];
        $this->view('user/index');
    }

    public function show()
    {
        $userId = filter_var($this->gets[0], FILTER_VALIDATE_INT);
        $this->user = (new UserModel())->find($userId);

        if (!is_int($userId) || !$this->user) {
            $this->pageInfo = ['title' => '无此用户'];
            flash('error', '无此用户');
            return $this->view('errors/flash');
        }

        return $this->view('user/show');
    }
}
